package com.yzy.fly.type;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

public enum RequestMappingAnnotationType {

    GET("get","org.springframework.web.bind.annotation.GetMapping"),
    POST("post","org.springframework.web.bind.annotation.PostMapping"),
    DELETE("delete","org.springframework.web.bind.annotation.DeleteMapping"),
    PUT("put","org.springframework.web.bind.annotation.PutMapping"),
    COMMON("common","org.springframework.web.bind.annotation.RequestMapping");

    @Setter@Getter
    private String type;
    @Setter@Getter
    private String value;

    RequestMappingAnnotationType(String type, String value){
        this.type = type;
        this.value = value;
    }

    public static RequestMappingAnnotationType type(String type){
        if (StringUtils.isBlank(type)) {
            return null;
        }
        RequestMappingAnnotationType sqlAnnotationType = null;
        RequestMappingAnnotationType[] values = values();
        try {
            for (int i = 0; i < values.length; i++) {
                RequestMappingAnnotationType value = values[i];
                if (value.getType().equals(type)) {
                    sqlAnnotationType = value;
                    break;
                }
            }
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            sqlAnnotationType = null;
        }
        return sqlAnnotationType;
    }


    public static RequestMappingAnnotationType typeIgnoreCase(String type){
        if (StringUtils.isBlank(type)) {
            return null;
        }
        RequestMappingAnnotationType value = null;
        try {
            RequestMappingAnnotationType[] values = values();
            for (int i = 0; i < values.length; i++) {
                if (values[i].getType().equalsIgnoreCase(type)) {
                    return values[i];
                }
            }
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            value = null;
        }
        return value;
    }

    public static void main(String[] args) {

    }
}
